//
//  BN_Mine_NavgationView.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-7-9.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_Mine_NavgationView.h"

@implementation BN_Mine_NavgationView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib {
    // UI
    self.bottomView.backgroundColor = APP_OBJECT_GREEN_COLOR;
    self.userNameLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:17];
    self.userPhotoImageView.layer.borderWidth = 3;
    self.userPhotoImageView.layer.cornerRadius = 30;
    self.userPhotoImageView.layer.borderColor = [[UIColor whiteColor] CGColor];
    
    // click
    [self.appSettingBtn addTarget:self action:@selector(appSettingAction) forControlEvents:UIControlEventTouchUpInside];
    [self.modifyBtn addTarget:self action:@selector(modifyAction) forControlEvents:UIControlEventTouchUpInside];
    [self.medalBtn addTarget:self action:@selector(medalAction) forControlEvents:UIControlEventTouchUpInside];
    [self.commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
    
    if (MAIN_VERSION > 6) {
        _medalCountLabel.frame = CGRectMake(CGRectGetMinX(_medalCountLabel.frame), CGRectGetMinY(_medalCountLabel.frame)-1, CGRectGetWidth(_medalCountLabel.frame), CGRectGetHeight(_medalCountLabel.frame));
        _commentCountLabel.frame = CGRectMake(CGRectGetMinX(_commentCountLabel.frame), CGRectGetMinY(_commentCountLabel.frame)-1, CGRectGetWidth(_commentCountLabel.frame), CGRectGetHeight(_commentCountLabel.frame));
    }
    
    // 数据
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    NSInteger userType = [userInfo.userType integerValue];
    switch (userType) {
        case ENUM_ROLE_LEADER:
            self.userNameLabel.text = userInfo.userName;
            self.userIntroduceLabel.text = userInfo.schoName;
            break;
        case ENUM_ROLE_CLASS_TEACHER:
        {
            self.userNameLabel.text = userInfo.userName;
            NSString *schoolName = [NSString stringWithFormat:@"%@",userInfo.schoName];
            self.userIntroduceLabel.text = [schoolName stringByAppendingString:userInfo.clasName];
        }
            break;
        case ENUM_ROLE_PARENT:
        {
#warning 生日字符（待新接口出炉后修改）
            self.userNameLabel.text = userInfo.userName;
            NSString *dateStr = FORMAT_STR([[NSUserDefaults standardUserDefaults]objectForKey:USERDEFAULTS_BIRTHDAYINFO]);
            if (![dateStr isEqualToString:@"(null)"] && dateStr) {
                if (dateStr.length < 19) {
                    if ([dateStr isEqualToString:@"未填写"]) {
                        dateStr = @"1991-11-01 00:00:00";
                    }else {
                        dateStr = [dateStr stringByAppendingString:@" 00:00:00"];
                    }
                    self.userIntroduceLabel.text = [IMB_TimeFormatModel clacBabyAge:dateStr];
                    return;
                }
                NSRange rang = NSMakeRange(0, 19);
                NSString *strRang = [dateStr substringWithRange:rang];
                self.userIntroduceLabel.text = [IMB_TimeFormatModel clacBabyAge:strRang];
            }
        } // 用户名称和用户简介
            break;
        default:
            break;
    }
}

#pragma mark
#pragma mark 通知群
- (void)appSettingAction {
    [[NSNotificationCenter defaultCenter]postNotificationName:K_MINE_OPEN_SETTING_VC object:nil];
}

- (void)modifyAction {
    [[NSNotificationCenter defaultCenter]postNotificationName:K_MINE_OPEN_MODIFY_VC object:nil];
}

- (void)medalAction {
    [[NSNotificationCenter defaultCenter]postNotificationName:K_MINE_OPEN_BABY_MEDAL_VC object:nil];
}

- (void)commentAction {
    [[NSNotificationCenter defaultCenter]postNotificationName:K_MINE_OPEN_TEACHER_COMMENT_VC object:nil];
}

#pragma mark 资源释放
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:K_MINE_OPEN_BABY_MEDAL_VC object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:K_MINE_OPEN_MODIFY_VC object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:K_MINE_OPEN_SETTING_VC object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:K_MINE_OPEN_TEACHER_COMMENT_VC object:nil];
}
@end
